home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / irit / dosintr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-16  |  6.6 KB  |  162 lines

  1. /******************************************************************************
  2. *   "Irit" - the 3d (not only polygonal) solid modeller.              *
  3. *                                          *
  4. * Written by:  Gershon Elber                 Ver 0.2, Mar. 1990   *
  5. *******************************************************************************
  6. * Procedures to handle the dos interface - print/change the current dir. etc. *
  7. ******************************************************************************/
  8.  
  9. #include <sys/types.h>
  10. #ifdef DJGCC
  11. #include <dir.h>
  12. #endif /* DJGCC */
  13. #ifdef __WINNT__
  14. #include <direct.h>
  15. #endif /* __WINNT__ */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <ctype.h>
  20. #include <errno.h>
  21. #include "program.h"
  22. #include "dosintr.h"
  23. #include "ctrl-brk.h"
  24. #include "windows.h"
  25.   
  26. #ifdef AMIGA
  27. #undef DOUBLE
  28. #ifdef __SASC
  29. #include <proto/dos.h>
  30. #endif /* __SASC */
  31. #ifdef __GNUC__
  32. #include <dos/dos.h>
  33. #include <inline/dos.h>
  34. #endif
  35. #endif /* AMIGA */
  36.  
  37. /*****************************************************************************
  38. * DESCRIPTION:                                                               M
  39. * Routine to change current directory                         M
  40. *                                                                            *
  41. * PARAMETERS:                                                                M
  42. *   s:        New directory to change to.                                    M
  43. *                                                                            *
  44. * RETURN VALUE:                                                              M
  45. *   void                                                                     M
  46. *                                                                            *
  47. * KEYWORDS:                                                                  M
  48. *   DosChangeDir                                                             M
  49. *****************************************************************************/
  50. void DosChangeDir(char *s)
  51. {
  52. #ifdef DJGCC
  53.     char cwd[LINE_LEN], *sptr;
  54.  
  55.     getcwd(cwd, LINE_LEN-1);               /* Save current position. */
  56.  
  57.     if (s[1] == ':')
  58.         sptr = &s[2];                /* Sptr points on the path only. */
  59.     else
  60.     sptr = s;
  61.  
  62.     if (strlen(sptr) != 0 && chdir(s))
  63.     WndwInputWindowPutStr("CHDIR: No Such Dir!");
  64.  
  65.     if (getcwd(s, LINE_LEN-1) == NULL) {      /* Test if directory is valid! */
  66.     WndwInputWindowPutStr("CHDIR: hardware (!?) error - ignored");
  67.     /* Restore old working directory: */
  68.     if (strlen(&cwd[2]) != 0)
  69.         chdir(cwd);                  /* If directory is not root... */
  70.     }
  71. #else
  72.     chdir(s);
  73. #endif /* DJGCC */
  74. }
  75.  
  76. /*****************************************************************************
  77. * DESCRIPTION:                                                               M
  78. * Procedure to return current time from last time, time was reset.         M
  79. * Time is reset if the given parameter is non zero. Time is returned in      M
  80. * seconds.                                     M
  81. *                                                                            *
  82. * PARAMETERS:                                                                M
  83. *   ResetTime:   To we want to resent the clock?                             M
  84. *                                                                            *
  85. * RETURN VALUE:                                                              M
  86. *   double:      Time since last reset/beginning of program.                 M
  87. *                                                                            *
  88. * KEYWORDS:                                                                  M
  89. *   DosGetTime                                                               M
  90. *****************************************************************************/
  91. double DosGetTime(double ResetTime)
  92. {
  93.     return IritCPUTime(!APX_EQ(ResetTime, 0.0));
  94. }
  95.  
  96. /*****************************************************************************
  97. * DESCRIPTION:                                                               M
  98. * Executes a system command.                                                 M
  99. *                                                                            *
  100. * PARAMETERS:                                                                M
  101. *   Str:       The system's command to execute.                              M
  102. *                                                                            *
  103. * RETURN VALUE:                                                              M
  104. *   void                                                                     M
  105. *                                                                            *
  106. * KEYWORDS:                                                                  M
  107. *   DosSystem                                                                M
  108. *****************************************************************************/
  109. void DosSystem(char *Str)
  110. {
  111.     char Buffer[LINE_LEN_LONG];
  112. #   ifdef __UNIX__
  113.         int pid = getpid();
  114. #   else
  115.         int pid = (int) IritRandom(0.0, 10000.0);
  116. #   endif /* __UNIX__ */
  117.  
  118.     sprintf(Buffer, "%s > irit_tmp.%d", Str, pid);
  119. #ifdef AMIGA
  120.     if (SystemTagList(Buffer, NULL))
  121. #else
  122.     if (system(Buffer))
  123. #endif
  124.     WndwInputWindowPutStr("Undefined error in attempt to run command");
  125.     else {
  126.     FILE *f;
  127.  
  128.     sprintf(Buffer, "irit_tmp.%d", pid);
  129.     if ((f = fopen(Buffer, "r")) != NULL) {
  130.         while (fgets(Buffer, LINE_LEN_LONG - 1, f)) {
  131.         if (Buffer[strlen(Buffer) - 1] < ' ')
  132.             Buffer[strlen(Buffer) - 1] = 0;         /* Remove CR. */
  133.         WndwInputWindowPutStr(Buffer);
  134.         }
  135.         fclose(f);
  136.  
  137.         sprintf(Buffer, "irit_tmp.%d", pid);
  138.         unlink(Buffer);
  139.     }
  140.     else
  141.         WndwInputWindowPutStr("Failed to read redirected output");
  142.     }
  143. }
  144.  
  145. /*****************************************************************************
  146. * DESCRIPTION:                                                               M
  147. * Routine to milli-seconds sleep.                         M
  148. *                                                                            *
  149. * PARAMETERS:                                                                M
  150. *   MiliSeconds:   How long do we want to sleep, in milliseconds?            M
  151. *                                                                            *
  152. * RETURN VALUE:                                                              M
  153. *   void                                                                     M
  154. *                                                                            *
  155. * KEYWORDS:                                                                  M
  156. *   MilisecondSleep                                                          M
  157. *****************************************************************************/
  158. void MilisecondSleep(RealType *MiliSeconds)
  159. {
  160.     IritSleep(REAL_PTR_TO_INT(MiliSeconds));
  161. }
  162.